package com.java110.mall.cart.cmd.cart;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.storeOrder.IUpdateStoreOrderBMO;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.po.storeOrder.StoreOrderPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

/**
 * 支付完成后 通知 确定订单功能
 *
 * 如果收货了 就自动 分账
 *
 * @ClassName PayNotifyOrderCmd
 * @Description TODO
 * @Author wuxw
 * @Date 2022/5/26 18:02
 * @Version 1.0
 * add by wuxw 2022/5/26
 **/
@Java110Cmd(serviceCode = "/cart/payNotifyOrder")
public class PayNotifyOrderCmd extends Cmd {

    @Autowired
    private IUpdateStoreOrderBMO updateStoreOrderBMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含orderId");

    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        StoreOrderPo storeOrderPo = BeanConvertUtil.covertBean(reqJson, StoreOrderPo.class);
        ResponseEntity<String> responseEntity = updateStoreOrderBMOImpl.update(storeOrderPo);
        cmdDataFlowContext.setResponseEntity(responseEntity);
    }
}
